var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
define(["require", "exports", "core/BaseWidget.class", "core/Functions.module"], function (require, exports, BaseWidget, Functions) {
    "use strict";
    var SideMenu = (function (_super) {
        __extends(SideMenu, _super);
        function SideMenu() {
            var _this = _super.apply(this, arguments) || this;
            _this.baseClass = "widgets-side_menu";
            _this.panels = new Array();
            _this.fullpanels = new Array();
            _this.halfpanels = new Array();
            _this.debug = false;
           
            return _this;
        }
        SideMenu.prototype.startup = function () {
            this.start();
            //---zhuboyu----
            this.domObj.find(".widgets-side_menu-footer-foldable-icon").click();
            //zhuboyu-----
        };
        SideMenu.prototype.start = function (config) {
            this.addToDom({
                root: this.widgetPath,
                media: {
                    foldImageURL: this.widgetPath + '/images/fold.png'
                },
                menuListData: this.config.menuListData || this.AppX.appConfig.menuBarWidgets
            });
            this.toast = this.AppX.runtimeConfig.toast;
            this.mainContainer = $(this.AppX.appConfig.mainContainer);
            this.initDomListen();
            this.ready();
            if (this.config.isFold) {
                this.domObj.find('.widgets-side_menu-footer-foldable-icon').data('isfold', true);
                this.domObj.addClass('widgets-side_menu-sidebar-small');
                this.mainContainer.css({
                    width: 'calc(100%-50px)',
                    left: '50px'
                });
            }
        };
        SideMenu.prototype.destroy = function () {
        };
        SideMenu.prototype.initDomListen = function () {
            var _this = this;
            this.domObj.find(".accordion").accordion({
                collapsible: true,
                active: false,
                heightStyle: "content",
                animate: 150,
                icons: {
                    header: "glyphicon glyphicon-chevron-left",
                    activeHeader: "glyphicon glyphicon-chevron-down"
                }
            });
            this.domObj.on('click', '.fire-on', function (e) {
                _this.itemOnClick(e);
            });
            this.domObj.on('click', '.widgets-side_menu-footer-foldable-icon', function (e) {
                _this.foldable(e);
            });
        };
        SideMenu.prototype.foldable = function (e) {
            var currentTarget = $(e.currentTarget);
            var isFold = currentTarget.data('isfold');
            if (isFold === true) {
                this.domObj.removeClass('widgets-side_menu-sidebar-small');
                this.mainContainer.css({
                    width: 'calc(100% - 180px)',// width: 'calc(100% - 250px)',
                    left: '180px'//left: '250px'
                });
            }
            else {
                this.domObj.addClass('widgets-side_menu-sidebar-small');
                this.mainContainer.css({
                    width: 'calc(100% - 50px)',
                    left: '50px'
                });
            }
            currentTarget.data('isfold', !isFold);
            //重置地图容器的宽度
            var scenediv = $(this.config.scenediv);
        	 var scenewidth =$("#mainContainer_horizontal").width()-$("#panel_Container").width();
        	 scenediv.css("width",scenewidth+"px");
        };
        SideMenu.prototype.itemOnClick = function (e) {
            var target = $(e.currentTarget);
            AppX.WidgetUse.useWidget($(target).attr("data-id"));
        };
        SideMenu.prototype.destroyWidget = function (widgetID) {
            this.domObj.find('.widgets-side_menu-item_header').removeClass('ui-state-active');
            this.panels[widgetID] = null;
            this.fullpanels[widgetID] = null;
            this.halfpanels[widgetID] = null;
            this.log('已销毁对象:ID = ' + widgetID);
        };
        SideMenu.prototype.addToDom = function (data) {
            var htmlString = _.template(this.template)(data);
            this.setHtml(htmlString, 'body');
        };
        return SideMenu;
    }(BaseWidget));
    return SideMenu;
});
